from hashlib import md5
from flask import Blueprint, render_template, request
from flask_cors import CORS

sgin_bp = Blueprint(
    'sgin_bp',
    __name__,
    url_prefix='/sgin'
)
CORS(sgin_bp)

@sgin_bp.route('/')
def index():

    return render_template('sgin.html')

@sgin_bp.route('/get')
def ajax_get():
    actions = request.values.get('actions')
    time = request.values.get('time')
    randstr = request.values.get('randstr')
    sgin = request.values.get('sgin')
    print(actions,time,randstr,sgin)
    if md5((actions+time+randstr).encode('utf-8')).hexdigest() == sgin:
        return request.url
    else:
        return render_template('is_spider.html')